#include "Expression.h"
#include "FeatureShape/QShapeVersion.h"

int Expression::expressionCount = 0;

Expression::Expression(bool bIsNativeExpression)
	: m_expression(QString(""))
	, m_value(QString(""))
	, m_targetFeature(nullptr)
	, m_bIsNativeExpression(bIsNativeExpression)
	, m_expressionID(expressionCount++)
{

}

Expression::Expression(QString expression, QString value, std::shared_ptr<Feature> targetFeature, bool bIsNativeExpression)
    : m_expression(expression)
    , m_value(value)
    , m_targetFeature(targetFeature)
    , m_bIsNativeExpression(bIsNativeExpression)
    , m_expressionID(expressionCount++)
{
}

void Expression::SetExpression(const QString& expression, const QList<std::shared_ptr<Feature>>& featureList, float newValue)
{
	m_expression = expression;
    m_featureList = featureList;
    m_value = QString::number(newValue);

    if (m_targetFeature)
    {
        m_targetFeature->GetValue() = newValue;
        // 检测是否需要运行额外操作
        if (m_targetFeature->m_modifyOperation)
        {
            m_targetFeature->m_modifyOperation();
        }
    }
}
